package com.xuan.pmh.activity;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;

import com.google.gson.Gson;
import com.xuan.pmh.bean.GsonBean;
import com.xuan.pmh.util.FinalValue;
import com.xuan.pmh.util.ShareUtil;

public abstract class BaseActivity extends Activity {

	/**
	 * 
	 * 根据自己项目的Activity的共同要求,将一些常规操作固定下来 所有带m的方法与父类方法类似,但有不同,是为使用方便而写
	 * 
	 */

	protected Gson gson = ShareUtil.gson;
	protected GsonBean gsonBean;
	protected OnClickListener onClick;
	protected LayoutInflater inflater;
	public String TAG;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		TAG = this.toString();
		inflater = LayoutInflater.from(this);
		setContentView(getLayoutId());
		onClick = new OnClickListener() {
			@Override
			public void onClick(View view) {
				// TODO Auto-generated method stub
				OnClickListener(view);
			}
		};
		setUI();

	}

	public final View mFindViewAndSetOnClick(int id) {
		View view = findViewById(id);
		view.setOnClickListener(onClick);
		return view;
	}

	public final void mFindViewAndSetOnClick(View view) {
		view.setOnClickListener(onClick);
	}

	protected void mPrint(String msg) {
		Log.v(TAG, msg);
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();

		Log.v("onResume", this.toString());
	}

	protected void onPause() {
		super.onPause();
		Log.v("onPause", this.toString());
	};

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		Log.v("onDestroy", this.toString());
	}

	public String getEditTextString(EditText et) {
		if (et.getText() != null)
			return et.getText().toString();
		return null;
	}

	public GsonBean getGsonBean(String result) {
		if (result != null) {
			return gson.fromJson(result, GsonBean.class);
		} else {
			GsonBean gsonBean = new GsonBean();
			gsonBean.state = FinalValue.FAIL;
			return gsonBean;
		}
	}

	public abstract int getLayoutId();

	public abstract void setUI();

	public abstract void OnClickListener(View view);
}
